<!--
 * @Author: wrh123 482597539@qq.com
 * @Date: 2024-01-21 15:33:31
 * @LastEditors: wrh123 482597539@qq.com
 * @LastEditTime: 2024-01-21 15:45:13
 * @FilePath: /vue-admin/src/views/distributed/components/addDistrbut.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="components">
    <el-dialog title="编辑" :visible="dialogVisible" width="30%" :before-close="handleClose">
      <!-- <span>这是一段信息</span> -->
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <!-- <el-form-item label="账户">
          <el-input size="mini" />
        </el-form-item> -->
        <el-form-item prop="resion" label="账号状态:">
          <el-select v-model="form.resion" size="mini">
            <el-option v-for="item in control" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item prop="userbalance" label="账户余额:">
          <el-input v-model="form.userbalance" size="mini" />
        </el-form-item>
        <el-form-item prop="userTagName" label="用户标签:">
          <el-select v-model="form.userTagName" size="mini" @focus="getuserTagName">
            <el-option v-for="(item, index) in userTagNames" :key="index" :label="item" :value="item" />
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose" size="mini">取 消</el-button>
        <el-button type="primary" @click="btnOK" size="mini">保存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { control } from '@/utils/index'
import { editDistributed } from '@/api/distributed'
import { getUserTagName, getUserTagNameSelect } from "@/api/Tradingacct";

export default {
  name: 'VueAdminAddDistrbut',
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    currOBJ: {
      type: Object,
      default: null
    },
    userTagName: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      form: {
        id: null,
        resion: 0,
        userbalance: null,
        userTagName: null, // 用户标签
      },
      userTagNames: [],
      accountMoney: '', // 交易资金
      rules: {
        resion: [{ required: true, message: '账号状态不可以为空', trigger: 'change' }],
        userbalance: [{ required: true, message: '账户余额不可以为空', trigger: 'blur' }]
      }
    }
  },
  computed: {
    control() {
      return control
    }
  },
  watch: {
    currOBJ(old, newVal) {
      this.form.id = old.id
      this.form.resion = +old.resion
      this.form.userbalance = old.userbalance
    },
    userTagName(old, newVal) {
      this.form.userTagName = old
    }
  },
  mounted() {
  },
  methods: {
    handleClose() {
      this.$refs.form.resetFields()
      this.$emit('update:dialogVisible', false)
    },
    async btnOK() {
      if (this.form.resion === 4) {
        if (this.form.userbalance > this.form.userbalance * 1.11 && this.form.challengeProject === 3) {
          this.$message.error('请输入正确的账户余额')
        } else {
          await this.$refs.form.validate()
          await editDistributed(this.form)
          this.$message.success('操作成功')
          this.$emit('refresh')
          this.handleClose()
        }
      } else {
        await this.$refs.form.validate()
        await editDistributed(this.form)
        this.$message.success('操作成功')
        this.$emit('refresh')
        this.handleClose()
      }
    },
    /**
     * @author 焦延龙 <19131965027@163.com>
     * @description 获取用户的标签
     * @date
     */
    async getuserTagName() {
      this.userTagNames = await getUserTagNameSelect(this.form.id)
      // console.log(this.userTagNames, 'qqq')
    },
    /**
     * @author 焦延龙 <19131965027@163.com>
     * @description
     * @date
     */
    async getWithdrawInfo(id) {
      const data = await getUserTagName(id)
      this.form.userTagName = data.paymentResult
    },
  }
}
</script>

<style lang="scss" scoped></style>
